package cn.edu.zjgsu.ito.service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;

import org.apache.poi.hssf.record.DBCellRecord;

import cn.edu.zjgsu.ito.model.AdminCourseManageModel;
import cn.edu.zjgsu.ito.model.TeaScoreInputModel;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.DbKit;
import com.jfinal.plugin.activerecord.Record;

public class AdminCourseManageService {

	private int flag;
	int judge1=0; int judge2=0; int judge3=0; int judge4=0;
	public List<Record> lookMajor() {
		List<Record> list=Db.find(AdminCourseManageModel.dao.lookMajorSql);
		if(list==null || list.size()<=0)
		{
			return null;
		}
		else{	
			return list;
		}
	}
	
	public List<Record> lookTerm() {
		List<Record> list=Db.find(AdminCourseManageModel.dao.lookTermSql);
		if(list==null || list.size()<=0)
		{
			return null;
		}
		else{	
			return list;
		}
	}
	
	public List<Record> lookCollege() {
		List<Record> list=Db.find(AdminCourseManageModel.dao.lookCollegeSql);
		if(list==null || list.size()<=0)
		{
			return null;
		}
		else{	
			return list;
		}
	}
	
	public List<Record> lookCourse() {
		List<Record> list=Db.find(AdminCourseManageModel.dao.lookCourseSql);
		if(list==null || list.size()<=0)
		{
			return null;
		}
		else{	
			return list;
		}
	}
	
	public List<Record> lookCourseByCollege(String collegeCode) {
		List<Record> list=Db.find(AdminCourseManageModel.dao.lookCourseByCollegeSql,collegeCode);
		if(list==null || list.size()<=0)
		{
			return null;
		}
		else{	
			return list;
		}
	}

	public List<Record> lookClassroom() {
		List<Record> list=Db.find(AdminCourseManageModel.dao.lookClassroomSql);
		if(list==null || list.size()<=0)
		{
			return null;
		}
		else{	
			return list;
		}
	}

	public List<Record> lookStudent() throws ParseException {
		java.text.SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
		List<Record> list=Db.find(AdminCourseManageModel.dao.lookStudentSql,0);
		for(int i=0;i<list.size();i++){
			String []b= new String[100];
			Date []date=new Date[100];
			Date dates=new Date();
			String Dates="";
			List<Record> lists = Db.find("select * from newpassportno where passportNo=?",list.get(i).getStr("passportNo"));			
			if(lists.size()>1){
				for(int j=0;j<lists.size();j++){
									b[j] = lists.get(j).getStr("time");
									date[j] = formatter.parse(b[j]);
								}
								System.out.println(lists.size());
								for(int a=0;a<lists.size()-1;a++){
									 dates = date[a];
									int c = (date[a+1]).compareTo(dates);						
									if(c>0){
										dates = date[a+1];
									}
									
								}								
								Dates = formatter.format(dates);
								System.out.println(Dates);
								Record newpassportNo = Db.findFirst("select * from newpassportno where time=?",Dates);
								System.out.println(newpassportNo.getStr("newpassportNo"));
								list.get(i).set("newpassportNo",newpassportNo.getStr("newpassportNo"));
				}
			else{
				System.out.println("[][][][][][][][][][]");
				Record newpassportNo = Db.findFirst("select * from newpassportno where passportNo=?",list.get(i).getStr("passportNo"));
				System.out.println("111111111");
				System.out.println(newpassportNo.getStr("newpassportNo"));
				list.get(i).set("newpassportNo",newpassportNo.getStr("newpassportNo"));
			}		
//			return list;
		}
		if(list==null || list.size()<=0)
		{
			return null;
		}
		else{	
			System.out.println("gegegeg");
			System.out.println(list);
			return list;
		}
	}

	public List<Record> lookTeacher() {
		List<Record> list=Db.find(AdminCourseManageModel.dao.lookTeacherSql);
		if(list==null || list.size()<=0)
		{
			return null;
		}
		else{	
			return list;
		}
	}

	public int saveStuTimetable(String student, String term, String courseNo, String courseName, String tNo, String teachers, String classroom, String firstClass, String lastClass, String firstWeek, String lastWeek, String week, String uuid) {
        if(!student.equals("")){
           flag=Db.update(AdminCourseManageModel.dao.insertStuTimetableSql,student,term,courseNo,courseName,tNo,teachers,classroom,firstClass,lastClass,firstWeek,lastWeek,week,uuid);
		if(flag==1){
			return 1;
		}
		else{
			return 0;
		} 
        }
		return 0;
	}

	public int saveTeaTimetable(String teacher, String term, String courseNo, String courseName, String classrooms, String firstClass, String lastClass, String firstWeek, String lastWeek, String week, String uuid) {		
		flag=Db.update(AdminCourseManageModel.dao.insertTeaTimetableSql,teacher,term,courseNo,courseName,classrooms,firstClass,lastClass,firstWeek,lastWeek,week,uuid);
		if(flag==1){
			return 1;
		}
		else{
			return 0;
		}
	}

	public int updateClassroomStatus(String classroom) {
		flag=Db.update(AdminCourseManageModel.dao.updateClassroomStatusSql,classroom);
		if(flag==1){
			return 1;
		}
		else{
			return 0;
		}
	}

	public String studentConflick(String student, String term, String week, String firstClass, String lastClass, String firstWeek, String lastWeek, String uuid) {
		
		String strFlag="ok";
		List<Record> list=Db.find(AdminCourseManageModel.dao.studentConflickSql2,student,term,uuid);
		//System.out.println("学生冲突___"+list.size());
		if(list==null || list.size()<=0)
		{
			return strFlag;
		}
		else{	
			for(int i=0;i<list.size();i++){
				flag=weeklyConflict(list.get(i),firstWeek,lastWeek);
				if(flag==0){
					int flag2=dayConflict(list.get(i),week);
					if(flag2==0){
						int flag3=sectionConflict(list.get(i),firstClass,lastClass);
						if(flag3==0){
							strFlag="error";
						}
					}				
				}
			}
			
		}
		return strFlag;
	}

	

	public Record lookTeaId(String tName) {
		List<Record> list=Db.find(AdminCourseManageModel.dao.lookTeaIdSql,tName);
		if(list==null || list.size()<=0)
		{
			return null;
		}
		else{	
			return list.get(0);
		}
	}

	public String teaConflick(String teacher, String term, String week, String firstClass, String lastClass,
			String firstWeek, String lastWeek, String uuid) {
		String strFlag="ok";
        System.out.println("为什么"+uuid);
		List<Record> list=Db.find(AdminCourseManageModel.dao.teacherConflickSql,teacher,term,uuid);
		//System.out.println(list.size());
		if(list==null || list.size()<=0)
		{
			return strFlag;
		}
		else{	
			for(int i=0;i<list.size();i++){
				flag=weeklyConflict(list.get(i),firstWeek,lastWeek);
				if(flag==0){
					int flag2=dayConflict(list.get(i),week);
					if(flag2==0){
						int flag3=sectionConflict(list.get(i),firstClass,lastClass);
						if(flag3==0){
							strFlag="error";
						}
					}				
				}
			}
			
		}
		return strFlag;
	}

	public String lookClassroomByOption(String classroom) {
		List<Record> list=Db.find(AdminCourseManageModel.dao.lookClassroomByOptionSql,classroom);
		if( "".equals(list.get(0).get("status")) || list.get(0).get("status")==null ){
			return "ok";
		}
		return "error";
	}

	public String classroomConflick(String classroom, String week, String firstClass, String lastClass, String firstWeek,
			String lastWeek, String term, String uuid) {
		String strFlag="ok";
		List<Record> list=Db.find(AdminCourseManageModel.dao.classroomConflickSql,classroom,term,uuid);
        System.out.println("教室冲突啊啊啊啊"+list.size());
		if(list==null || list.size()<=0){
			return strFlag;
		}
		else{
			for(int i=0;i<list.size();i++){
				flag=weeklyConflict(list.get(i),firstWeek,lastWeek);
				if(flag==0){
					int flag2=dayConflict(list.get(i),week);
					if(flag2==0){
						int flag3=sectionConflict(list.get(i),firstClass,lastClass);
						if(flag3==0){
							strFlag="error";
						}
					}				
				}
			}
		}
		return strFlag;
	}

	
	private int sectionConflict(Record record, String firstClass, String lastClass) {
		int a = 1;
		// System.out.println(Integer.parseInt(firstWeek)>=Integer.parseInt(list.get(i).getStr("startWeek"))&&Integer.parseInt(firstWeek)<=Integer.parseInt(list.get(i).getStr("endWeek")));
		if (Integer.parseInt(firstClass) >= Integer.parseInt(record.getStr("startLesson"))
				&& Integer.parseInt(firstClass) <= Integer.parseInt(record.getStr("endLesson"))) {
			a = 0;
		} 
		else {
			if (Integer.parseInt(lastClass) >= Integer.parseInt(record.getStr("startLesson"))
					&& Integer.parseInt(lastClass) <= Integer.parseInt(record.getStr("endLesson"))) {
				a = 0;
			}
		}
		if (Integer.parseInt(firstClass) < Integer.parseInt(record.getStr("startLesson"))
				&& Integer.parseInt(lastClass) > Integer.parseInt(record.getStr("endLesson"))) {
			a=0;
		} 
		return a;
	}

	private int dayConflict(Record record, String week) {
		int a=1;		
		if(week.equals(record.getStr("whichDay"))){
			a=0;
		}
		
		return a;
	}

	private int weeklyConflict(Record record, String firstWeek, String lastWeek) {
		int a = 1;
		// System.out.println(Integer.parseInt(firstWeek)>=Integer.parseInt(list.get(i).getStr("startWeek"))&&Integer.parseInt(firstWeek)<=Integer.parseInt(list.get(i).getStr("endWeek")));
		if (Integer.parseInt(firstWeek) >= Integer.parseInt(record.getStr("startWeek"))
				&& Integer.parseInt(firstWeek) <= Integer.parseInt(record.getStr("endWeek"))) {
			a = 0;
		} 
		else {
			if (Integer.parseInt(lastWeek) >= Integer.parseInt(record.getStr("startWeek"))
					&& Integer.parseInt(lastWeek) <= Integer.parseInt(record.getStr("endWeek"))) {
				a = 0;
			}
		}
		if (Integer.parseInt(firstWeek) < Integer.parseInt(record.getStr("startWeek"))
				&& Integer.parseInt(lastWeek) > Integer.parseInt(record.getStr("endWeek"))) {
			a=0;
		} 
		
		return a;
	}



	

	public int judegRoster(String tNo, String term, String courseName) {
		List<Record> list=Db.find(AdminCourseManageModel.dao.judegRosterSql,tNo,term,courseName);
		
		if(list==null || list.size()<=0)
		{
			System.out.println("该花名册不存在");
			return 1;
		}
		else{	
			System.out.println("该花名册已存在");
			return 0;
		}
	}
	
	public int insertRoster(String tNo,String term,String courseNo, String courseName, String student, String uuid) {
        if(!student.equals("")){
           List<Record> list=Db.find(AdminCourseManageModel.dao.lookStudentBypassportNo,student);
		List<Record> list2=Db.find(AdminCourseManageModel.dao.lookStudentBypassportNo,student);

		flag=Db.update(AdminCourseManageModel.dao.insertRosterSql,tNo,term,courseNo,courseName,list.get(0).get("sNo"),student,list.get(0).get("lastName"),list.get(0).get("firstName"),list.get(0).get("majorNo"),list.get(0).get("majorName"),uuid);
		
		if(flag==1){
			return 1;
		}
		else{
			return 0;
		} 
        }
		return 0;
	}

	public int insertMajorTimetable(String term, String majorName, String courseName, String tNo, String teachers,
			String firstClass, String lastClass, String firstWeek, String lastWeek, String week, String classroom, String uuid) {

		List<Record> list1=Db.find(AdminCourseManageModel.dao.lookcourseNoSql,courseName);
		//System.out.println(list1.get(0).get("courseNo"));
		List<Record> list2=Db.find(AdminCourseManageModel.dao.lookmajorNoSql,majorName);
		//System.out.println(list2.get(0).get("majorNo"));
		flag=Db.update(AdminCourseManageModel.dao.insertMajorTimetableSql,term,list2.get(0).get("majorNo"),majorName,list1.get(0).get("courseNo"),courseName,tNo,teachers,classroom,firstClass,lastClass,firstWeek,lastWeek,week,uuid);

		if(flag==1){
			return 1;
		}
		else{
			return 0;
		}
	}

	public List<Record> lookmajorTimetable(String majorNo, String term) {
		List<Record> list=Db.find(AdminCourseManageModel.dao.lookmajorTimetableSql,majorNo,term);
		System.out.println("该专业共有"+list.size()+"门课程");
		if(list==null || list.size()<=0)
		{
			return null;
		}
		else{	
			return list;
		}
	}
	public List<Record> lookmajorTimetableByUUID(String uuid) {
		List<Record> list=Db.find(AdminCourseManageModel.dao.lookmajorTimetableByOptionSql,uuid);
		//System.out.println("该专业共有"+list.size()+"门课程");
		if(list==null || list.size()<=0)
		{
			return null;
		}
		else{	
			return list;
		}
	}
	

	public int deleteTeacherTimetable(String uuid) {
		flag=Db.update(AdminCourseManageModel.dao.deleteTeacherTimetableSql,uuid);
		if(flag==1){
			return 1;
		}
		else{
			return 0;
		}
	}

	public int deleteStudentTimetable(String uuid) {
		flag=Db.update(AdminCourseManageModel.dao.deleteStudentTimetableSql,uuid);
		if(flag==1){
			return 1;
		}
		else{
			return 0;
		}
	}

	public int judegTeacherTimetable(String tNo, String term, String courseName) {
		System.out.println("判断该教师这门课还存在另一个时间段");
		List<Record> list=Db.find(AdminCourseManageModel.dao.judegTeacherTimetableSql,tNo,term,courseName);
		
		if(list==null || list.size()<=0)
		{
			return 1;
		}
		else{	
			return 0;
		}
	}

	public void deleteRoster(String uuid ) {
		flag=Db.update(AdminCourseManageModel.dao.deleteRosterSql,uuid);
		
	}

	public void deleteMajorTimetable( String uuid) {
		flag=Db.update(AdminCourseManageModel.dao.deleteMajorTimetableSql,uuid);
		
	}

	public List<Record> lookmajorNo(String majorNo) {
		List<Record> list=Db.find(AdminCourseManageModel.dao.lookmajorNameSql,majorNo);
		if(list==null || list.size()<=0)
		{
			return null;
		}
		else{	
			return list;
		}
	}

	public List<Record> lookCourseName(String courseNo) {
		List<Record> list=Db.find(AdminCourseManageModel.dao.lookCourseNameSql,courseNo);		
		if(list==null || list.size()<=0)
		{
			return null;
		}
		else{	
			return list;
		}
	}

	public List<Record> lookCourseStuInfo(String uuid) throws ParseException {
		java.text.SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
		List<Record> list=Db.find(AdminCourseManageModel.dao.lookCourseStuInfoSql,uuid);
		//增加学号
		if(list.size() > 0){
			for(int i = 0;i < list.size();i++){
				String sNo = Db.findFirst("select * from student_info where passportNo=?",list.get(i).getStr("passportNo")).getStr("sNo");
				list.get(i).set("sNo",sNo);
			}
		}
		
		for(int i=0;i<list.size();i++){
			String []b= new String[100];
			Date []date=new Date[100];
			Date dates=new Date();
			String Dates="";
			List<Record> lists = Db.find("select * from newpassportno where passportNo=?",list.get(i).getStr("passportNo"));
			if(lists.size()>1){
				for(int j=0;j<lists.size();j++){
									b[j] = lists.get(j).getStr("time");
									date[j] = formatter.parse(b[j]);
								}
								System.out.println(lists.size());
								for(int a=0;a<lists.size()-1;a++){
									 dates = date[a];
									int c = (date[a+1]).compareTo(dates);
									if(c>0){
										dates = date[a+1];
									}
							
								}								
								Dates = formatter.format(dates);
								Record newpassportNo = Db.findFirst("select * from newpassportno where time=?",Dates);
								list.get(i).set("newpassportNo",newpassportNo.getStr("newpassportNo"));
				}
			else{
				Record newpassportNo = Db.findFirst("select * from newpassportno where passportNo=?",list.get(i).getStr("passportNo"));
				list.get(i).set("newpassportNo",newpassportNo.getStr("newpassportNo"));
			}
		}
		if(list==null || list.size()<=0)
		{
			return null;
		}
		else{	
			System.out.println("aaazzz");
			System.out.println(list);
			return list;
		}
	}

	public List<Record> lookCourseTeaInfo(String uuid) {
		List<Record> list=Db.find(AdminCourseManageModel.dao.lookCourseTeaInfoSql,uuid);
		if(list==null || list.size()<=0)
		{
			return null;
		}
		else{	
			return list;
		}
	}

	public Record lookTeaName(String teaId) {
		List<Record> list=Db.find(TeaScoreInputModel.dao.lookTeaNameSql,teaId);
		if(list==null || list.size()<=0)
		{
			return null;
		}
		else{	
			return list.get(0);
		}
	}

	public List<Record> lookCourseStuByUUID(String uuid) {
		List<Record> list=Db.find(AdminCourseManageModel.dao.lookCourseStuByUUIDSql,uuid);

		if(list==null || list.size()<=0)
		{
			return null;
		}
		else{	
			return list;
		}
	}
	
	public List<Record> lookCourseTeaByUUID(String uuid) {
		List<Record> list=Db.find(AdminCourseManageModel.dao.lookCourseTeaByUUIDSql,uuid);

		if(list==null || list.size()<=0)
		{
			return null;
		}
		else{	
			return list;
		}
	}

	public int updateStuTimetable(String week, String firstClass, String lastClass, String firstWeek, String lastWeek, String teachers, String classroom, String uuid, String tNo) {
		flag=Db.update(AdminCourseManageModel.dao.updateStuTimetableSql,week,firstClass,lastClass,firstWeek,lastWeek,teachers,classroom,tNo,uuid);
		if(flag==1){
			return 1;
		}
		else{
			return 0;
		}
	}

	public int updateTeaTimetable(String week, String firstClass, String lastClass, String firstWeek, String lastWeek, String classroom, String uuid) {
		flag=Db.update(AdminCourseManageModel.dao.updateTeaTimetableSql,week,firstClass,lastClass,firstWeek,lastWeek,classroom,uuid);
		if(flag==1){
			return 1;
		}
		else{
			return 0;
		}
	}

	public int updateMajorTimetable(String week, String firstClass, String lastClass, String firstWeek, String lastWeek,
			String teachers, String classroom, String uuid, String tNo) {
		flag=Db.update(AdminCourseManageModel.dao.updateMajorTimetableSql,week,firstClass,lastClass,firstWeek,lastWeek,teachers,classroom,tNo,uuid);
		if(flag==1){
			return 1;
		}
		else{
			return 0;
		}
	}

	public int updateStuTimetableByPassport(String week, String firstClass, String lastClass, String firstWeek,
			String lastWeek, String teachers, String classroom, String uuid, String passportNo, String tNo) {
		flag=Db.update(AdminCourseManageModel.dao.updateStuTimetableByPassportSql,week,firstClass,lastClass,firstWeek,lastWeek,tNo,teachers+",",classroom,uuid,passportNo);
		if(flag==1){
			return 1;
		}
		else{
			return 0;
		}
	}
	
	private int updateTeaTimetableByTNo(String week, String firstClass, String lastClass, String firstWeek,
			String lastWeek, String classroom, String uuid, String tNo) {
		flag=Db.update(AdminCourseManageModel.dao.updateTeaTimetableByTNoSql,week,firstClass,lastClass,firstWeek,lastWeek,classroom,uuid,tNo);
		System.out.println("修改老师:"+flag);
		if(flag==1){
			return 1;
		}
		else{
			return 0;
		}
	}

	public int deleteStudentTimetableBypassport(String uuid, String passportNo) {
		flag=Db.update(AdminCourseManageModel.dao.deleteStudentTimetableBypassportSql,uuid,passportNo);
		if(flag==1){
			return 1;
		}
		else{
			return 0;
		}
	}
	
	private int deleteteacherTimetableByTNo(String uuid, String tNo) {
		flag=Db.update(AdminCourseManageModel.dao.deleteteacherTimetableByTNoSql,uuid,tNo);
		if(flag==1){
			return 1;
		}
		else{
			return 0;
		}
	}
    public int yesRoomNoTeaNoStu(String week, String firstClass, String lastClass, String firstWeek, String lastWeek,
			String teachers, String classroom, String uuid, String tNo,String[] student,String[] teacher,String term) {
            
            String stuJudge="ok";
            String teaJudge="ok";
            String classroomJudge="ok";
            List<Record> list=Db.find(AdminCourseManageModel.dao.lookmajorTimetableByOptionSql,uuid);
          
            if(list.get(0).getStr("startLesson").equals(firstClass)
                    &&list.get(0).getStr("endLesson").equals(lastClass)
                    &&list.get(0).getStr("startWeek").equals(firstWeek)
                    &&list.get(0).getStr("endWeek").equals(lastWeek)
                    &&list.get(0).getStr("whichDay").equals(week)){
                System.out.println("只修改教室");
                judge1=updateStuTimetable(week,firstClass,lastClass,firstWeek,lastWeek,teachers,classroom,uuid,tNo);
                System.out.println("judge1"+judge1);
                judge2=updateTeaTimetable(week,firstClass,lastClass,firstWeek,lastWeek,classroom,uuid);
                System.out.println("judge2"+judge2);
                judge3=updateMajorTimetable(week,firstClass,lastClass,firstWeek,lastWeek,teachers,classroom,uuid,tNo);
                System.out.println("judge3"+judge3);
                return 1;
            }
            else{
                System.out.println("修改课程的教室和时间");
                for (int i = 0; i < student.length; i++) {

                    stuJudge=studentConflick(student[i],term,week,firstClass,lastClass,firstWeek,lastWeek,uuid);
                    if(stuJudge.equals("error")){
                        break;
                    }
                }
                for (int i = 0; i < teacher.length; i++) {
                    Record r = lookTeaId(teacher[i]);
                    teaJudge = teaConflick(r.getStr("tNo"), term, week, firstClass, lastClass, firstWeek, lastWeek, uuid);
                    if(teaJudge.equals("error")){
                        break;
                    }
                }
                if(stuJudge.equals("error")||teaJudge.equals("error")){
                    return 0;
                }else{
                    judge1=updateStuTimetable(week,firstClass,lastClass,firstWeek,lastWeek,teachers,classroom,uuid,tNo);
                    System.out.println("judge1"+judge1);
                    judge2=updateTeaTimetable(week,firstClass,lastClass,firstWeek,lastWeek,classroom,uuid);
                    System.out.println("judge2"+judge2);
                    judge3=updateMajorTimetable(week,firstClass,lastClass,firstWeek,lastWeek,teachers,classroom,uuid,tNo);
                    System.out.println("judge3"+judge3);
                    return 1;
                }
            }
        
   
    }
	public int noRoomNoTeaNoStu(String week, String firstClass, String lastClass, String firstWeek, String lastWeek,
			String teachers, String classroom, String uuid, String tNo,String[] student,String[] teacher,String term) {
		
        String stuJudge="ok";
        String teaJudge="ok";
        String classroomJudge="ok";
        for (int i = 0; i < student.length; i++) {
            if(student.length==1&&student[0].equals("")){
                break;
            }
            stuJudge=studentConflick(student[i],term,week,firstClass,lastClass,firstWeek,lastWeek,uuid);
            if(stuJudge.equals("error")){
                break;
            }
        }
        for (int i = 0; i < teacher.length; i++) {
            if(teacher.length==1&&teacher[0].equals("")){
                break;
            }
            Record r = lookTeaId(teacher[i]);
            teaJudge = teaConflick(r.getStr("tNo"), term, week, firstClass, lastClass, firstWeek, lastWeek, uuid);
            if(teaJudge.equals("error")){
                break;
            }
        }
        if(!classroom.equals("")){
            classroomJudge = classroomConflick(classroom, week, firstClass, lastClass,
							firstWeek, lastWeek,term,uuid);
        }
        
        System.out.println("学生:"+stuJudge+"老师:"+teaJudge+"教室:"+classroomJudge);
        if(stuJudge.equals("error")||teaJudge.equals("error")||classroomJudge.equals("error")){
            return 0;
        }else{
            judge1=updateStuTimetable(week,firstClass,lastClass,firstWeek,lastWeek,teachers,classroom,uuid,tNo);
            System.out.println("judge1"+judge1);
            judge2=updateTeaTimetable(week,firstClass,lastClass,firstWeek,lastWeek,classroom,uuid);
            System.out.println("judge2"+judge2);
            judge3=updateMajorTimetable(week,firstClass,lastClass,firstWeek,lastWeek,teachers,classroom,uuid,tNo);
            System.out.println("judge3"+judge3);
            
            return 1;
        }
		

		
		
		
	}

	public String noRoomNoTeaYesStu(String week, String firstClass, String lastClass, String firstWeek, String lastWeek,
			String teachers, String classroom, String uuid, List<Record> stuList, String[] student, String term, String courseName, String courseNo, String tNo,String majorName) {
		String stuMessage="";
        if(!teachers.equals("")){
            teachers=teachers+",";
        }		
		List majorList = new ArrayList();
		//新增多出来的学生
		for(int i=0;i<student.length;i++){
			int exist=0;
            if(stuList==null){
                String stuJudge=studentConflick(student[i],term,week,firstClass,lastClass,firstWeek,lastWeek,uuid);
				if(stuJudge.equals("ok")){			
					
					System.out.println(student[i]+"无冲突");
					String major=lookStuMajor(student[i]);
					majorList.add(major);
					judge1=saveStuTimetable(student[i],term,courseNo,courseName,tNo,teachers,classroom,firstClass,lastClass,firstWeek,lastWeek,week,uuid);
					
				}
				else{
					stuMessage+=student[i]+" ";		
					//System.out.println("xxxxxx"+stuMessage);
				}		
            }
            else{
                for(int j=0;j<stuList.size();j++){	
                    if(student[i].equals(stuList.get(j).getStr("passportNo"))){
                        exist=1;
                        break;
                    }					
                }
                if(exist==1){
				System.out.println(student[i]+"已存在");
				String major=lookStuMajor(student[i]);
				majorList.add(major);
				judge1=updateStuTimetableByPassport(week,firstClass,lastClass,firstWeek,lastWeek,teachers,classroom,uuid,student[i],tNo);
				//System.out.println(judge1);
                }
                else{
				System.out.println(student[i]+"不存在");
				String stuJudge=studentConflick(student[i],term,week,firstClass,lastClass,firstWeek,lastWeek,uuid);
				//System.out.println(stuJudge);
				if(stuJudge.equals("ok")){			
					
					System.out.println(student[i]+"无冲突");
					String major=lookStuMajor(student[i]);
					majorList.add(major);
					judge1=saveStuTimetable(student[i],term,courseNo,courseName,tNo,teachers,classroom,firstClass,lastClass,firstWeek,lastWeek,week,uuid);
					
				}
				else{
					stuMessage+=student[i]+" ";		
					System.out.println("xxxxxx"+stuMessage);
				}		
                } 
            }
			
		}
		deleteMajorTimetable(uuid);
 
        if(!classroom.equals("")&&!teachers.equals("")){
            
        }
        else{
            majorList.add(majorName);
        }
        
        if(student.length==1&&student[0].equals("")){
            
        }
        else{
            for(int i=0;i<majorList.size();i++){
			for(int j=i+1;j<majorList.size();j++){
				if(majorList.get(i).toString().equals(majorList.get(j).toString())){
					majorList.remove(j);
					j--;
				}
			}
		}
        }
		
        if(teachers.equals("")){
            
        }
        else{
            teachers=teachers.substring(0,teachers.lastIndexOf(","));
        }		
        if(student.length==1&&student[0].equals("")){
            insertMajorTimetable(term, majorName, courseName, tNo, teachers, firstClass, lastClass, firstWeek, lastWeek, week, classroom, uuid);
        }
        else{
            for (int i = 0; i < majorList.size(); i++) {
                System.out.println(majorList.get(i));
                insertMajorTimetable(term, majorList.get(i).toString(), courseName, tNo, teachers, firstClass, lastClass, firstWeek, lastWeek, week, classroom, uuid);
            }
        }
		
		//原先在现在不在的学生删除
        if(stuList!=null){
            for(int i=0;i<stuList.size();i++){
			int exist2=0;
			for(int j=0;j<student.length;j++){
				if(student[j].equals(stuList.get(i).getStr("passportNo"))){
					exist2=1;
					break;
				}	
			}
			if(exist2==0){
				judge1 = deleteStudentTimetableBypassport(uuid,stuList.get(i).getStr("passportNo"));
			}
		}
        }
		if(!"".equals(stuMessage)){
            System.out.println("进来了");
			stuMessage+="这些学生有冲突";
		}
        System.out.println(stuMessage);
		return stuMessage;
	}

	public String noRoomYesTeaNoStu(String week, String firstClass, String lastClass, String firstWeek, String lastWeek,
			String teachers, String classroom, String uuid, List<Record> teaList, String[] teacher, String term, String courseName ,String courseNo, String tNo) {
		String teaMessage="";
		String nowTeachers="";
		//新增多出来的教师
		for (int i = 0; i < teacher.length; i++) {
			int exist = 0;
            if(teaList==null){
                Record r = lookTeaId(teacher[i]);
                String teaJudge = teaConflick(r.getStr("tNo"), term, week, firstClass, lastClass, firstWeek, lastWeek, uuid);
				System.out.println(teaJudge);
				if (teaJudge.equals("ok")) {
					nowTeachers+=teacher[i]+",";
					judge1 = saveTeaTimetable(r.getStr("tNo"), term, courseNo, courseName, classroom, firstClass, lastClass,
							firstWeek, lastWeek, week, uuid);
					System.out.println("老师新增:"+judge1);
				} else {
					teaMessage += teacher[i] + " ";
				}	
            }
            else{
                for (int j = 0; j < teaList.size(); j++) {
				Record r = lookTeaName(teaList.get(j).getStr("tNo"));
				if (teacher[i].equals(r.getStr("tName"))) {
					exist = 1;
					break;
				}
			}
			Record r = lookTeaId(teacher[i]);
			if (exist == 1) {
				System.out.println(teacher[i] + "已存在");
				nowTeachers+=teacher[i]+",";
				judge1 = updateTeaTimetableByTNo(week, firstClass, lastClass, firstWeek, lastWeek,
						classroom, uuid, r.getStr("tNo"));
				// System.out.println(judge1);
			} else {
				System.out.println(teacher[i] + "不存在");
                if(r!=null){
                    String teaJudge = teaConflick(r.getStr("tNo"), term, week, firstClass, lastClass, firstWeek, lastWeek, uuid);
                
                    System.out.println(teaJudge);
                    if (teaJudge.equals("ok")) {
                        nowTeachers+=teacher[i]+",";
                        judge1 = saveTeaTimetable(r.getStr("tNo"), term, courseNo, courseName, classroom, firstClass, lastClass,
							firstWeek, lastWeek, week, uuid);
                        System.out.println("老师新增:"+judge1);
                    } else {
                        teaMessage += teacher[i] + " ";
                    }
                }
			}
            }
			
		}
		// 原先在现在不在的老师删除
        if(teaList!=null){
            for (int i = 0; i < teaList.size(); i++) {
                int exist2 = 0;
			
                for (int j = 0; j < teacher.length; j++) {
				
                    Record r = lookTeaName(teaList.get(i).getStr("tNo"));
                    if (teacher[j].equals(r.getStr("tName"))) {
                        exist2 = 1;
                        break;
                    }
                }
                if (exist2 == 0) {
                    System.out.println(teaList.get(i).getStr("tNo"));
                    judge1 = deleteteacherTimetableByTNo(uuid, teaList.get(i).getStr("tNo"));
                }
            }
        }
        if(nowTeachers.equals("")){
           
        }
        else{
            nowTeachers=nowTeachers.substring(0,nowTeachers.lastIndexOf(","));
        }
		judge1=updateStuTimetable(week,firstClass,lastClass,firstWeek,lastWeek,nowTeachers,classroom,uuid,tNo);
		System.out.println("judge1"+judge1);
		
		judge3=updateMajorTimetable(week,firstClass,lastClass,firstWeek,lastWeek,nowTeachers,classroom,uuid,tNo);
		System.out.println("judge3"+judge3);
		if(!"".equals(teaMessage)){
			teaMessage+="这些老师有冲突";
		}
		
		return teaMessage;
	}

	public String noRoomYesTeaYesStu(String week, String firstClass, String lastClass, String firstWeek,
			String lastWeek, String teachers, String classroom, String uuid, List<Record> stuList, String[] student,
			String term, String courseName, List<Record> teaList, String[] teacher, String courseNo, String tNo,String majorName) {
		String teaMessage="";
		String nowTeachers="";
		//新增多出来的教师
		for (int i = 0; i < teacher.length; i++) {
			int exist = 0;
            if(teaList!=null){
			for (int j = 0; j < teaList.size(); j++) {
				Record r = lookTeaName(teaList.get(j).getStr("tNo"));
				if (teacher[i].equals(r.getStr("tName"))) {
					exist = 1;
					break;
				}
			}
			Record r = lookTeaId(teacher[i]);
			if (exist == 1) {
				System.out.println(teacher[i] + "已存在");
				nowTeachers+=teacher[i]+",";
				judge1 = updateTeaTimetableByTNo(week, firstClass, lastClass, firstWeek, lastWeek,
						classroom, uuid, r.getStr("tNo"));
				// System.out.println(judge1);
			} else {
				System.out.println(teacher[i] + "不存在");
                if(r!=null){
                    String teaJudge = teaConflick(r.getStr("tNo"), term, week, firstClass, lastClass, firstWeek, lastWeek, uuid);
                    System.out.println(teaJudge);
                    if (teaJudge.equals("ok")) {
                        nowTeachers+=teacher[i]+",";
                        judge1 = saveTeaTimetable(r.getStr("tNo"), term, courseNo, courseName, classroom, firstClass, lastClass,
							firstWeek, lastWeek, week, uuid);
                        System.out.println("老师新增:"+judge1);
                    } else {
                        teaMessage += teacher[i] + " ";
                    }
                }
			}
            }
            else{
                Record r = lookTeaId(teacher[i]);
                String teaJudge = teaConflick(r.getStr("tNo"), term, week, firstClass, lastClass, firstWeek, lastWeek, uuid);
                    System.out.println(teaJudge);
                    if (teaJudge.equals("ok")) {
                        nowTeachers+=teacher[i]+",";
                        judge1 = saveTeaTimetable(r.getStr("tNo"), term, courseNo, courseName, classroom, firstClass, lastClass,
							firstWeek, lastWeek, week, uuid);
                        System.out.println("老师新增:"+judge1);
                    } else {
                        teaMessage += teacher[i] + " ";
                    }
            }
		}
		// 原先在现在不在的老师删除
        if(teaList!=null){
            for (int i = 0; i < teaList.size(); i++) {
                int exist2 = 0;
			
                for (int j = 0; j < teacher.length; j++) {
				
                    Record r = lookTeaName(teaList.get(i).getStr("tNo"));
                    if (teacher[j].equals(r.getStr("tName"))) {
                        exist2 = 1;
                        break;
                    }
                }
                if (exist2 == 0) {
                    System.out.println(teaList.get(i).getStr("tNo"));
                	judge1 = deleteteacherTimetableByTNo(uuid, teaList.get(i).getStr("tNo"));
                }
            }
        }
		if(teacher.length==1&&teacher[0].equals("")){
           
        }
        else{
            nowTeachers=nowTeachers.substring(0,nowTeachers.lastIndexOf(","));
        }
		String strJudge=noRoomNoTeaYesStu(week,firstClass,lastClass,firstWeek,lastWeek,nowTeachers,classroom,uuid,stuList,student,term,courseName,courseNo,tNo,majorName);							
		//judge3=updateMajorTimetable(week,firstClass,lastClass,firstWeek,lastWeek,nowTeachers,classroom,uuid,tNo);
		System.out.println("judge3"+judge3);
		if(!"".equals(teaMessage)){
			teaMessage+="这些老师有冲突";
		}
		
		return teaMessage+strJudge;
	}

	public String noRoomNoTeaYesStuExist(String week, String firstClass, String lastClass, String firstWeek,
			String lastWeek, String teachers, String classroom, String uuid, List<Record> stuList, String[] student,
			String term, String courseName) {
		String nowStudents="";
		//新增多出来的学生
		for(int i=0;i<student.length;i++){
			int exist=0;
            if(stuList!=null){
                for(int j=0;j<stuList.size();j++){	
                    if(student[i].equals(stuList.get(j).getStr("passportNo"))){
                        exist=1;
                        break;
                    }					
                }
                if(exist==1){
				/*System.out.println(student[i]+"已存在");*/
                    nowStudents+=student[i]+",";
                }
                else{
				/*System.out.println(student[i]+"不存在");*/
                    String stuJudge=studentConflick(student[i],term,week,firstClass,lastClass,firstWeek,lastWeek,uuid);
				//System.out.println(stuJudge);
                    if(stuJudge.equals("ok")){	
                        nowStudents+=student[i]+",";
					
                    }
					
                }
            }
            else{
                String stuJudge=studentConflick(student[i],term,week,firstClass,lastClass,firstWeek,lastWeek,uuid);
				//System.out.println(stuJudge);
                    if(stuJudge.equals("ok")){	
                        nowStudents+=student[i]+",";
					
                    }
            }
		}
		if("".equals(nowStudents)){
			return "";
		}
		else{
			return nowStudents;
		}
		
	}

	public String noRoomYesTeaNoStuExist(String week, String firstClass, String lastClass, String firstWeek,
			String lastWeek, String teachers, String classroom, String uuid, List<Record> teaList, String[] teacher,
			String term, String courseName) {
		String nowTeachers="";
		//新增多出来的教师
        if(teacher.length==1&&teacher[0].equals("")){
            return "";
        }
		for (int i = 0; i < teacher.length; i++) {
			int exist = 0;
            if(teaList==null){
                Record r = lookTeaId(teacher[i]);
               	String teaJudge = teaConflick(r.getStr("tNo"), term, week, firstClass, lastClass, firstWeek, lastWeek, uuid);
				System.out.println(teaJudge);
				if (teaJudge.equals("ok")) {
					nowTeachers+=teacher[i]+",";
					
				} 
            }
            else{
                for (int j = 0; j < teaList.size(); j++) {
				Record r = lookTeaName(teaList.get(j).getStr("tNo"));
				if (teacher[i].equals(r.getStr("tName"))) {
					exist = 1;
					break;
				}
			}
			Record r = lookTeaId(teacher[i]);
			if (exist == 1) {
				System.out.println(teacher[i] + "已存在");
				nowTeachers+=teacher[i]+",";
			} else {
				System.out.println(teacher[i] + "不存在");
				String teaJudge = teaConflick(r.getStr("tNo"), term, week, firstClass, lastClass, firstWeek, lastWeek, uuid);
				System.out.println(teaJudge);
				if (teaJudge.equals("ok")) {
					nowTeachers+=teacher[i]+",";
					
				} 
			}
            }
			
		}	
		if("".equals(nowTeachers)){
			return "";
		}
		else{
			return nowTeachers;
		}
	}

	public String looktNos(String teachers) {
		String tNo="";
		String[] teacher=new String[200];
		teacher=teachers.split(",");
		for (int i = 0; i < teacher.length; i++) {
			Record a=lookTeaId(teacher[i]);
			tNo+=a.getStr("tNo")+",";
		}
		return tNo;
	}

	public List<Record> lookTeacherByCollege(String collegeCode) {
		List<Record> list = null;
		if(collegeCode.equals("全部")){
			list = Db.find("select * from teacher_info");
		}else{
			list =Db.find(AdminCourseManageModel.dao.lookTeacherByCollegeSql,collegeCode);
		}
		
		if(list==null || list.size()<=0)
		{
			return null;
		}
		else{	
			return list;
		}
	}

	public List<Record> lookClassroomByType(String classroomType) {
		List<Record> list=Db.find(AdminCourseManageModel.dao.lookClassroomByTypeSql,classroomType);
		if(list==null || list.size()<=0)
		{
			return null;
		}
		else{	
			return list;
		}
	}

	public List<Record> lookStudentByDateAndMajorNo(String eduStartDate, String majorNo) throws ParseException {
		java.text.SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
		if(eduStartDate.equals("全部")&&majorNo.equals("全部")){
            List<Record> list=Db.find(AdminCourseManageModel.dao.lookStudentSql,0);
            for(int i=0;i<list.size();i++){
    			String []b= new String[100];
    			Date []date=new Date[100];
    			Date dates=new Date();
    			String Dates="";
    			List<Record> lists = Db.find("select * from newpassportno where passportNo=?",list.get(i).getStr("passportNo"));
    			if(lists.size()>1){
    				for(int j=0;j<lists.size();j++){
    									b[j] = lists.get(j).getStr("time");
    									date[j] = formatter.parse(b[j]);
    								}
    								System.out.println(lists.size());
    								for(int a=0;a<lists.size()-1;a++){
    									 dates = date[a];
    									int c = (date[a+1]).compareTo(dates);
    									System.out.println("-------");
    									System.out.println(c);
    									System.out.println("++++++++++++++++++++++++++++");
    									if(c>0){
    										dates = date[a+1];
    									}
    									System.out.println(dates);
    									System.out.println("================");
    								}
    								System.out.println("qqqqqqqqq");
    								System.out.println(dates);
    								System.out.println("444444444");
    								Dates = formatter.format(dates);
    								System.out.println(Dates);
    								Record newpassportNo = Db.findFirst("select * from newpassportno where time=?",Dates);
    								System.out.println("111111111");
    								System.out.println(newpassportNo.getStr("newpassportNo"));
    								list.get(i).set("newpassportNo",newpassportNo.getStr("newpassportNo"));
    				}
    			else{
    				System.out.println("[][][][][][][][][][]");
    				Record newpassportNo = Db.findFirst("select * from newpassportno where passportNo=?",list.get(i).getStr("passportNo"));
    				System.out.println("111111111");
    				System.out.println(newpassportNo.getStr("newpassportNo"));
    				list.get(i).set("newpassportNo",newpassportNo.getStr("newpassportNo"));
    			}		
    			
    		}
			if(list==null || list.size()<=0)
			{
				return null;
			}
			else{	
				return list;
			}
        }
		if(eduStartDate.equals("全部")&&!majorNo.equals("全部")){
			System.out.println("入学年份不考虑");
			List<Record> list=Db.find(AdminCourseManageModel.dao.lookStudentByDateAndMajorNoSql1,majorNo,0);
			 for(int i=0;i<list.size();i++){
	    			String []b= new String[100];
	    			Date []date=new Date[100];
	    			Date dates=new Date();
	    			String Dates="";
	    			List<Record> lists = Db.find("select * from newpassportno where passportNo=?",list.get(i).getStr("passportNo"));
	    			if(lists.size()>1){
	    				for(int j=0;j<lists.size();j++){
	    									b[j] = lists.get(j).getStr("time");
	    									date[j] = formatter.parse(b[j]);
	    								}
	    								System.out.println(lists.size());
	    								for(int a=0;a<lists.size()-1;a++){
	    									 dates = date[a];
	    									int c = (date[a+1]).compareTo(dates);
	    									System.out.println("-------");
	    									System.out.println(c);
	    									System.out.println("++++++++++++++++++++++++++++");
	    									if(c>0){
	    										dates = date[a+1];
	    									}
	    									System.out.println(dates);
	    									System.out.println("================");
	    								}
	    								System.out.println("qqqqqqqqq");
	    								System.out.println(dates);
	    								System.out.println("444444444");
	    								Dates = formatter.format(dates);
	    								System.out.println(Dates);
	    								Record newpassportNo = Db.findFirst("select * from newpassportno where time=?",Dates);
	    								System.out.println("111111111");
	    								System.out.println(newpassportNo.getStr("newpassportNo"));
	    								list.get(i).set("newpassportNo",newpassportNo.getStr("newpassportNo"));
	    				}
	    			else{
	    				System.out.println("[][][][][][][][][][]");
	    				Record newpassportNo = Db.findFirst("select * from newpassportno where passportNo=?",list.get(i).getStr("passportNo"));
	    				System.out.println("111111111");
	    				System.out.println(newpassportNo.getStr("newpassportNo"));
	    				list.get(i).set("newpassportNo",newpassportNo.getStr("newpassportNo"));
	    			}		
	    			
	    		}
			if(list==null || list.size()<=0)
			{
				return null;
			}
			else{	
				return list;
			}
		}
		if(majorNo.equals("全部")&&!eduStartDate.equals("全部")){
			System.out.println("专业不考虑");
			List<Record> list=Db.find(AdminCourseManageModel.dao.lookStudentByDateAndMajorNoSql2,eduStartDate,0);
			 for(int i=0;i<list.size();i++){
	    			String []b= new String[100];
	    			Date []date=new Date[100];
	    			Date dates=new Date();
	    			String Dates="";
	    			List<Record> lists = Db.find("select * from newpassportno where passportNo=?",list.get(i).getStr("passportNo"));
	    			if(lists.size()>1){
	    				for(int j=0;j<lists.size();j++){
	    									b[j] = lists.get(j).getStr("time");
	    									date[j] = formatter.parse(b[j]);
	    								}
	    								System.out.println(lists.size());
	    								for(int a=0;a<lists.size()-1;a++){
	    									 dates = date[a];
	    									int c = (date[a+1]).compareTo(dates);
	    									System.out.println("-------");
	    									System.out.println(c);
	    									System.out.println("++++++++++++++++++++++++++++");
	    									if(c>0){
	    										dates = date[a+1];
	    									}
	    									System.out.println(dates);
	    									System.out.println("================");
	    								}
	    								System.out.println("qqqqqqqqq");
	    								System.out.println(dates);
	    								System.out.println("444444444");
	    								Dates = formatter.format(dates);
	    								System.out.println(Dates);
	    								Record newpassportNo = Db.findFirst("select * from newpassportno where time=?",Dates);
	    								System.out.println("111111111");
	    								System.out.println(newpassportNo.getStr("newpassportNo"));
	    								list.get(i).set("newpassportNo",newpassportNo.getStr("newpassportNo"));
	    				}
	    			else{
	    				System.out.println("[][][][][][][][][][]");
	    				Record newpassportNo = Db.findFirst("select * from newpassportno where passportNo=?",list.get(i).getStr("passportNo"));
	    				System.out.println("111111111");
	    				System.out.println(newpassportNo.getStr("newpassportNo"));
	    				list.get(i).set("newpassportNo",newpassportNo.getStr("newpassportNo"));
	    			}		
	    			
	    		}
			if(list==null || list.size()<=0)
			{
				return null;
			}
			else{	
				return list;
			}
		}
		if(!eduStartDate.equals("全部")&&!majorNo.equals("全部")){
			System.out.println("入学年份和专业都考虑");
			List<Record> list=Db.find(AdminCourseManageModel.dao.lookStudentByDateAndMajorNoSql,eduStartDate,majorNo,0);
			 for(int i=0;i<list.size();i++){
	    			String []b= new String[100];
	    			Date []date=new Date[100];
	    			Date dates=new Date();
	    			String Dates="";
	    			List<Record> lists = Db.find("select * from newpassportno where passportNo=?",list.get(i).getStr("passportNo"));
	    			if(lists.size()>1){
	    				for(int j=0;j<lists.size();j++){
	    									b[j] = lists.get(j).getStr("time");
	    									date[j] = formatter.parse(b[j]);
	    								}
	    								System.out.println(lists.size());
	    								for(int a=0;a<lists.size()-1;a++){
	    									 dates = date[a];
	    									int c = (date[a+1]).compareTo(dates);
	    									System.out.println("-------");
	    									System.out.println(c);
	    									System.out.println("++++++++++++++++++++++++++++");
	    									if(c>0){
	    										dates = date[a+1];
	    									}
	    									System.out.println(dates);
	    									System.out.println("================");
	    								}
	    								System.out.println("qqqqqqqqq");
	    								System.out.println(dates);
	    								System.out.println("444444444");
	    								Dates = formatter.format(dates);
	    								System.out.println(Dates);
	    								Record newpassportNo = Db.findFirst("select * from newpassportno where time=?",Dates);
	    								System.out.println("111111111");
	    								System.out.println(newpassportNo.getStr("newpassportNo"));
	    								list.get(i).set("newpassportNo",newpassportNo.getStr("newpassportNo"));
	    				}
	    			else{
	    				System.out.println("[][][][][][][][][][]");
	    				Record newpassportNo = Db.findFirst("select * from newpassportno where passportNo=?",list.get(i).getStr("passportNo"));
	    				System.out.println("111111111");
	    				System.out.println(newpassportNo.getStr("newpassportNo"));
	    				list.get(i).set("newpassportNo",newpassportNo.getStr("newpassportNo"));
	    			}		
	    			
	    		}
			System.out.println(list.size());
			if(list==null || list.size()<=0)
			{
				return null;
			}
			else{	
				return list;
			}
		}
		return null;
	}

	public int addTerm(String term) {
		try{
			flag=Db.update(AdminCourseManageModel.dao.addTermSql,term,0,0);
			return 1;
		}catch(Exception e){
			System.out.println(e);
			return 0;
		}
	}

	public int deleteTerm(String term) {
		flag=Db.update(AdminCourseManageModel.dao.deleteTermSql,term);
		
		if(flag==1){
			return 1;
		}
		else{
			return 0;
		}
	}

	public String lookCurrentTerm() {
		List<Record> list=Db.find(AdminCourseManageModel.dao.lookCurrentTermSql,1);
		System.out.println(list.get(0).getStr("termValue"));
		if(list==null || list.size()<=0)
		{
			return null;
		}
		else{	
			return list.get(0).getStr("termValue");
		}
	}

	public int setCurrentTerm(String term) {
		//Db.update(AdminCourseManageModel.dao.updateCurrentSql,1);
		Db.update(AdminCourseManageModel.dao.setInvalidTermSql);
		flag=Db.update(AdminCourseManageModel.dao.setCurrentTermSql,term);
		if(flag==1){
			return 1;
		}
		else{
			return 0;
		}
	}

	public int setInvalidTerm(String term) {
		flag=Db.update(AdminCourseManageModel.dao.setInvalidTermSql,term);
		if(flag==1){
			return 1;
		}
		else{
			return 0;
		}
	}

	public String lookStuMajor(String student) {
		List<Record> list=Db.find(AdminCourseManageModel.dao.lookStudentBypassportNo,student);
		if(list==null || list.size()<=0)
		{
			return null;
		}
		else{	
			return list.get(0).getStr("majorName");
		}
	}

	public int lookStuGrade(String uuid) {
		List<Record> list=Db.find(AdminCourseManageModel.dao.lookStuGradeNo,uuid);
		System.out.println("成绩:"+list.size());
		if(list==null || list.size()<=0)
		{
			return 1;
		}
		else{	
			return 0;
		}
	}

	//新建一门考试----杨昆鹏
	//testType：1:正常考试  2:补考    testLock: 0：未录入  1：已录入   2：超时未录入 
	public void courseTest(String termValue,String courseNo,String tNo,String uuid){
		
		Random ran=new Random();
		int a =ran.nextInt(99999999);
		String str = "";
        for (int i = 0; i < 10; i++) {// 你想生成几个字符的，就把4改成几，如果改成1,那就生成一个随机字母．
            str = str + (char) (Math.random() * 26 + 'a');
        }
        int b =ran.nextInt(99999999);
		String testNo = a + str + b;
		Record newTest = new Record().set("termValue",termValue).set("courseNo",courseNo).set("tNo",tNo)
				.set("uuid",uuid).set("testType",1).set("testLock",0).set("testNo",testNo);
		Record courseTemp = Db.findFirst("select * from course where courseNo=?",courseNo);
		String courseName = courseTemp.getStr("courseName");
		Record end = new Record().set("termValue",termValue).set("courseNo",courseNo)
				.set("testNo",testNo).set("courseName",courseName).set("endDate","未设置截止时间");
		
		Db.save("test",newTest);
		Db.save("course_end",end);
	}
	
	
	
	//删除考试
	public void deleteTest(String uuid){
		
		Db.update("delete from test where uuid=?",uuid);
	}
	
	//修改考试
	public void updataTest(String uuid){
		Record updataTest = Db.findFirst("select * from teacher_timetable where uuid=?",uuid);
		String tNo = updataTest.getStr("tNo");
		Db.update("update test set tNo=? where uuid=?",tNo,uuid);
	}
}

	

	


	

	

	

	

	

